{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
    <h3 class="pb-3">编辑售酒端</h3>
    <table class="layui-table layui-table-form">
        <tr>
            <td class="layui-td-gray-2">售酒机管理员<font>*</font></td>
            <td>
                <select name="pid" lay-verify="required" lay-reqText="请完善上级管理员ID">
                    <option value="">请选择</option>
                    {volist name="userList" id="v"}
                    <option value="{$v.id}" {eq name="$detail.pid" value="$v.id" }selected{/eq}>{$v.user_name}</option>
                    {/volist}
                </select>
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">头像</td>
            <td colspan="5" style="vertical-align:top">
                <div class="layui-upload">
                    <button type="button" class="layui-btn layui-btn-sm" id="upload_btn_thumb">选择图片</button>
                    <div class="layui-upload-list" id="upload_box_thumb">
                        <img src="{$detail.avatar}"
                             onerror="javascript:this.src='{__GOUGU__}/gougu/images/nonepic600x360.jpg';this.onerror=null;"
                             style="width:100px;max-width:100px"/>
                        <input type="hidden" name="avatar" value="{$detail.avatar}" >
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">名称<font>*</font></td>
            <td>
                <input type="text" name="user_name" lay-verify="required" lay-reqText="请完善名称" value="{$detail.user_name}"
                       autocomplete="off" placeholder="请输入名称" class="layui-input">
            </td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">手机号<font>*</font></td>
            <td><input type="text" name="mobile" lay-verify="required" lay-reqText="请完善手机号" value="{$detail.mobile}"
                       autocomplete="off" placeholder="请输入手机号" class="layui-input"></td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">登录密码<font>*</font></td>
            <td><input type="text" name="password" lay-verify="required" lay-reqText="请完善登录密码" value="{$detail.password}"
                       autocomplete="off" placeholder="请输入登录密码" class="layui-input"></td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">详细地址<font>*</font></td>
            <td><input type="text" name="address" lay-verify="required" lay-reqText="请完善详细地址" value="{$detail.address}"
                       autocomplete="off" placeholder="请完善详细地址" class="layui-input"></td>
        </tr>
        <tr>
            <td class="layui-td-gray-2">状态</td>
            <td>
                <input type="radio" name="status" value="1" title="正常" {eq name="$detail.status" value="1" }checked{/eq}>
                <input type="radio" name="status" value="0" title="禁用" {eq name="$detail.status" value="0" }checked{/eq}>
            </td>
        </tr>
    </table>
    <div class="py-3">
        <input type="hidden" name="id" value="{$detail.id}"/>
        <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
    var moduleInit = ['tool'];

    function gouguInit() {
        var form = layui.form, tool = layui.tool;
        var layer = layui.layer;
        var element = layui.element;
        //上传缩略图
        var upload_thumb = layui.upload.render({
            elem: '#upload_btn_thumb',
            url: '/admin/api/upload',
            done: function (res) {
                //如果上传失败
                if (res.code == 1) {
                    return layer.msg('上传失败');
                }
                //上传成功
                $('#upload_box_thumb input').attr('value', res.data.filepath);
                $('#upload_box_thumb img').attr('src', res.data.filepath);
            }
        });

        //监听提交
        form.on('submit(webform)', function (data) {

            let callback = function (e) {
                layer.msg(e.msg);
                if (e.code == 0) {
                    tool.sideClose(1000);
                }
            }
            tool.post("/admin/user_one/edit", data.field, callback);
            return false;
        });
    }
</script>
{/block}
<!-- /脚本 -->